package znbkTestPaperCtfd.presenter;

import android.util.Log;

import znbkListCtfd.IWrongTopicTutoringPresenter;
import com.example.lancooznbk.view.base.ILoadPaperView;
import com.lancoo.rxretrofitlibrary.Api.UserInfo;
import com.lancoo.rxretrofitlibrary.http.HttpManager;
import com.lancoo.rxretrofitlibrary.listener.HttpOnNextListener;

import znbkTestPaperCtfd.activity.WrongTopicTutoringPaperActivity;
import znbkTestPaperCtfd.entity.WrongTopicTutoringPaperEntity;
import znbkTestPaperCtfd.entity.WrongTopicTutoringModel;
import znbkTestPaperCtfd.api.WrongTopicTutoringPaperApi;
import znbkTestPaperInfor.ZnbkPaperInfor;

/**
 * Created by Administrator on 2018\2\23 0023.
 */

public class WrongTopicTutoringPaperPresenter implements IWrongTopicTutoringPresenter {

    private ILoadPaperView view;

    public WrongTopicTutoringPaperPresenter(ILoadPaperView view) {
        this.view = (ILoadPaperView) view;
    }

    @Override
    public void getData(boolean isShowLoading) {
        if (isShowLoading) view.showLoading();

        HttpOnNextListener<WrongTopicTutoringPaperEntity> httpOnNextListener = new HttpOnNextListener<WrongTopicTutoringPaperEntity>() {
            @Override
            public void onNext(WrongTopicTutoringPaperEntity wrongTopicTutoringPaperEntity) {


                if (wrongTopicTutoringPaperEntity.getPrimitiveQues().getTKQue() != null) {
                    view.hideLoading();
//                    if(AnswerState==2) {
//                        int RecQuesCount = wrongTopicTutoringPaperEntity.getRecQues().size();
//                        for (int i = 0; i < RecQuesCount; i++) {
//                            if (wrongTopicTutoringPaperEntity.getRecQues().get(i).getAnswerState() == AnswerState) {
//                                view.loadPaperData(wrongTopicTutoringPaperEntity.getRecQues().get(i));
//                            }
//                        }
//                    }else{
                        view.loadPaperData(wrongTopicTutoringPaperEntity);
//                    }
                }else {
                    view.showNoData("暂无内容");
                }
            }


            @Override
            public void onError(Throwable e) {
                super.onError(e);
                view.showNetError();
            }

            @Override
            public void onComplete() {
                super.onComplete();
                Log.d("TML","end: "+System.currentTimeMillis());
            }
        };

        WrongTopicTutoringPaperApi api = new WrongTopicTutoringPaperApi(httpOnNextListener, (WrongTopicTutoringPaperActivity)view);

        api.setWrongTopicTutoringModel(WrongTopicTutoringModel.getWrongTopicTutoringModelJson(ZnbkPaperInfor.QuesID, UserInfo.SubjectId,
                ZnbkPaperInfor.ItemFrom,ZnbkPaperInfor.CreatTime,UserInfo.StuId,UserInfo.StageNo,UserInfo.StuName,
                ZnbkPaperInfor.ListStuAnswerCtfd));

        HttpManager httpManager = HttpManager.getInstance();
        httpManager.doHttpDeal(api);
    }

    @Override
    public void getMoreData() {
        getData(false);
    }

    @Override
    public void getDataByStatus(int position) {
        getData(false);
    }

    @Override
    public void getDataByQuesType(String quesTypeId) {
        getData(false);
    }


}